<template>
    <div>
        <h1>某个学生信息查询</h1>
        <el-row>
            <el-col :span="6" :offset="8">
                <el-input v-model="stu_id" placeholder="请输入要查询的学号"></el-input>
            </el-col>
            <el-col :span="6" :offset="1">
                <el-button @click="getStuInfo">搜索</el-button>
            </el-col>
        </el-row>
        <div class="result_wrap" v-if="show">
            <img :src="result[0].stu_head_img" alt="" width="200px" height="200px" />
            <div class="table_wrap">
                <el-table :data="result" style="width: 100%; height: 50px;">
                    <el-table-column prop="stu_id" label="学号">
                    </el-table-column>
                    <el-table-column prop="stu_name" label="姓名">
                    </el-table-column>
                    <el-table-column prop="stu_sex" label="性别">
                    </el-table-column>
                    <el-table-column prop="stu_jg" label="籍贯">
                    </el-table-column>
                    <el-table-column prop="stu_date" label="出生日期">
                        <template slot-scope="scope">
                            <p>{{ $moment(scope.row.stu_date).format("YYYY-MM-DD") }}</p>
                        </template>
                    </el-table-column>
                    <el-table-column prop="stu_gbf" label="男或女朋友">
                    </el-table-column>
                    <el-table-column prop="stu_hobby" label="爱好">
                    </el-table-column>
                </el-table>
            </div>
        </div>
    </div>
</template>

<script>
import { req_stu_info_personal } from "@/api/stuInfo.js"
export default {
    data() {
        return {
            stu_id: '',
            result: [],
            show: false,
        }
    },
    methods: {
        async getStuInfo() {
            console.log(this.stu_id);
            let result = await req_stu_info_personal(this.stu_id);
            console.log(result);
            // this.result = result.data;
            // this.show = true;
            // console.log(this.result);
            // 当服务器没有数据时
            if(result.data.length >0){
                this.result = result.data;
                this.show = true;
            }else{
                this.$message({
                    message:'该学号不存在，请重新输入',
                    type:'error',
                })
            }

        },
    }
}
</script>

<style lang="scss" scoped>
div {
    text-align: center;

    h1 {
        height: 20px;
        text-align: center;
    }

    img {
        margin-top: 10px;
    }

    .el-table {
        overflow: inherit;
        font-size: 10px;
        text-align: center;

        .el-table__body-wrapper {
            height: 60px;
        }
    }
}
</style>